package com.sgb.kjwl.view.ui.activity.self.authentication;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityAuthCenterBinding;
import com.sgb.kjwl.di.self.DaggerSelfComponent;
import com.sgb.kjwl.di.self.SelfModule;
import com.sgb.kjwl.model.entity.user.SupplierAuthEntity;
import com.sgb.kjwl.viewmodel.self.AuthCenterModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.util.SharedPreferenceUtil;

import javax.inject.Inject;

public class AuthCenterActivity extends AppActivity {
    private ActivityAuthCenterBinding binding;
    @Inject
    AuthCenterModel viewModel;
    private SupplierAuthEntity supplierAuthEntity;

    @Override
    protected boolean statusBarDark() {
        return false;
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerSelfComponent.builder()
                .appComponent(appComponent)
                .selfModule(new SelfModule(this))
                .build()
                .inject(this);
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, AuthCenterActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(AuthCenterActivity.this, R.layout.activity_auth_center);
        binding.setViewModel(viewModel);
        binding.include.actionBarTitle.setText(getResources().getString(R.string.self_auth_center));
        binding.include.actionBarImageLeft.setVisibility(View.VISIBLE);
        binding.include.actionBarImageLeft.setOnClickListener(this);
        binding.realAuthLayout.setOnClickListener(this);
        binding.purchaseAuthLayout.setOnClickListener(this);
        binding.supplierAuthLayout.setOnClickListener(this);
    }

    @Override
    protected void init() {
        SharedPreferenceUtil.init(this);
        int role = SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.LOGIN_ROLE, 0);
        if (role == 0) {

        } else if (role == 1) {

        } else if (role == 2) {

        } else if (role == 3) {
            viewModel.getSupplierAuthModel();
        }
    }

    public void showSupplierAuthView(SupplierAuthEntity data) {
        this.supplierAuthEntity = data;
        if (supplierAuthEntity == null) {
            binding.stateView.setText("去认证");
        } else {
            if (data.getStatus().equals("1")) {
                binding.stateView.setText("认证中");
            } else if (data.getStatus().equals("2")) {
                binding.stateView.setText("认证失败");
            } else if (data.getStatus().equals("3")) {
                binding.stateView.setText("认证成功");
            }
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.action_bar_image_left:
                finish();
                break;
            case R.id.real_auth_layout:
                Toast.makeText(AuthCenterActivity.this, "功能定制中...", Toast.LENGTH_SHORT).show();
                break;
            case R.id.purchase_auth_layout:
                // SupplierAuthActivity.start(AuthCenterActivity.this);
                Toast.makeText(AuthCenterActivity.this, "功能定制中...", Toast.LENGTH_SHORT).show();
                break;
            case R.id.supplier_auth_layout:
//                if (supplierAuthEntity != null) {
//                    AuthInfoActivity.start(AuthCenterActivity.this);
//                    EventBus.getDefault().postSticky(AuthEvent.make().setMessageTag(EventConstant.EVENT_SELF_AUTH_INFO).setMessageData(supplierAuthEntity));
//                } else {
//                    SupplierAuthActivity.start(AuthCenterActivity.this);
//                }
                break;
        }
    }
}
